Tata Infotech Previous Years Solved Sample Placement Papers
-
What is the key difference between a while loop and a do-while loop in Java?
A: The syntax used to define the loop
B: The number of iterations performed
C: The condition check timing
D: The ability to use the break statement
Ans: C -
Which loop construct guarantees that the loop body is executed at least once?
A: for loop
B: while loop
C: do-while loop
D: continue statement
Ans: C -
What is an infinite loop?
A: A loop that executes only once
B: A loop that never terminates naturally
C: A loop that contains an unreachable code block
D: A loop that uses the continue statement
Ans: B -
Which statement is used to exit a loop prematurely?
A: return statement
B: continue statement
C: break statement
D: exit statement
Ans: C -
Which loop construct is best suited for iterating over an array or a collection?
A: for loop
B: while loop
C: do-while loop
D: continue statement
Ans: A -
How do you declare an array in Java?
A: int arrayName;
B: int[] arrayName;
C: int arrayName[];
D: Both b and c
Ans: D -
Which method is used to get the length of an array in Java?
A: length()
B: size()
C: getLength()
D: length
Ans: D -
How do you initialize an array in Java?
A: int[] arr = (1,2,3,4,5);
B: int arr = {1,2,3,4,5};
C: int[] arr = new int[]{1,2,3,4,5};
D: int arr = new int(5);
Ans: C -
What happens when you try to access an array element with an index that is out of bounds?
A: It returns -1
B: It returns a null value
C: It throws an exception
D: It initializes a new array
Ans: C -
How can you check if two arrays are equal in Java?
A: Use the == operator
B: Use the .equals() method
C: Use Arrays.equals() method
D: Compare each element one by one
Ans: C -
What is encapsulation in Java?
A: The process of combining data and methods into a single unit
B: The process of hiding data and methods within a class
C: The process of creating multiple instances of a class
D: The process of reusing code from existing classes
Ans: B -
What is inheritance in Java?
A: The process of creating multiple instances of a class
B: The process of hiding data and methods within a class
C: The process of reusing code from existing classes
D: The process of combining data and methods into a single unit
Ans: C -
What is polymorphism in Java?
A: The ability of a class to inherit properties and behaviors from another class
B: The process of hiding data and methods within a class
C: The process of creating multiple instances of a class
D: The ability of an object to take on many forms
Ans: D -
Starting from which Java version can an interface contain method implementations?
A: Java 5
B: Java 7
C: Java 8
D: Java 9
Ans: C -
What is the purpose of the instanceof operator?
A: Multiply instances
B: Compare two object references
C: Check if an object is an instance of a specific class or interface
D: To create a new instance of a class
Ans: C -
Which keyword is used to declare a class variable?
A: volatile
B: transient
C: static
D: final
Ans: C -
Which keyword is used to prevent a class from being inherited?
A: final
B: abstract
C: class
D: extends
Ans: A